#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


class Solution {
public:
    vector<vector<int>> fourSum(vector<int>& nums, int target)
    {
        sort(nums.begin(), nums.end());
        vector<vector<int>> vv;
        int len = nums.size();
        for (int i = 0; i < len; )
        {
            for (int j = i + 1; j < len; )
            {
                int left = j + 1; int right = len - 1;
                while (left < right)
                {
                    long long sum = nums[left] + nums[right] + nums[j];
                    if (nums[i] + sum > target) right--;
                    else if (nums[i] + sum < target) left++;
                    else
                    {
                        vv.push_back({ nums[i],nums[j],nums[left],nums[right] });
                        right--; left++;
                        while (left < right && nums[left] == nums[left - 1]) left++;
                        while (left < right && nums[right] == nums[right + 1]) right--;
                    }
                }
                ++j;
                while (j < len && nums[j] == nums[j - 1]) j++;
            }
            i++;
            while (i < len && nums[i] == nums[i - 1]) i++;
        }
        return vv;
    }
};
int main()
{

	return 0;
}
